<template>
  <div class="favorite-box">
    {{n}}
  </div>
</template>

<script>
  export default {
    data(){
      return {
        n: 0
      }
    },
    methods:{
      add(v){
        this.n += v
      }
    },
    created(){
      //注册事件
      window.eventBus.$on('add',this.add)
    },
    beforeDestroy(){
      //注销事件
      window.eventBus.$off('add',this.add)
    }
  }
</script>

<style lang="sass" scoped>
.favorite-box
  position: fixed
  right: 5px
  top: 5px
  width: 30px
  line-height: 30px
  text-align: center
  background: red
  color: #fff
  border-radius: 50%
</style>
